//
//  UITableViewController+TPTableViewController.m
//  CloudAtCostPanel
//
//  Created by leonardo on 2017/2/20.
//  Copyright © 2017年 tanpengsccd. All rights reserved.
//

#import "UIViewController+TPUtility.h"
#import <objc/runtime.h>
static NSString * alertVC_HUD_loadingKey = @"alertVC_HUD_loadingKey";
@implementation UIViewController (TPUtility)
//- (void)viewDidLoad {
//    DDLogVerbose(@"%@ viewDidLoad" , NSStringFromClass(self.class));
//    
//    [super viewDidLoad];
//    self.view.backgroundColor = COLOUR_BACKGROUND;
//    // Do any additional setup after loading the view.
//}
//
//- (void)viewWillAppear:(BOOL)animated{
//    
//    DDLogVerbose(@"%@ viewWillAppear" , NSStringFromClass(self.class));
//    [super viewWillAppear:animated];
//}
//
//-(void)viewDidAppear:(BOOL)animated{
//    DDLogVerbose(@"%@ viewDidAppear" , NSStringFromClass(self.class));
//    [super viewDidAppear:animated];
//}
//
//-(void)viewWillDisappear:(BOOL)animated{
//    DDLogVerbose(@"%@ viewWillDisappear" , NSStringFromClass(self.class));
//    [super viewWillDisappear:animated];
//}
//
//-(void)viewDidDisappear:(BOOL)animated{
//    DDLogVerbose(@"%@ viewDidDisappear" , NSStringFromClass(self.class));
//    [super viewDidAppear:animated];
//    
//}
//
//- (void)dealloc{
//    DDLogVerbose(@"%@ dealloc" , NSStringFromClass(self.class));
//    
//}
//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}

- (void)showHudTipsWithResModel_error:(TPBaseNetModel_res *)resModel{
    TPAlertView * alertVC = [[TPAlertView alloc]initOkWithTitle:resModel.error_description subtitle:nil];
//    [self presentViewController:alertVC animated:YES completion:nil];
    [[TPAlertViewController defaultCautionViewController]showAlertView:alertVC animated:YES];
}

- (void)showHudTips:(NSString *)str{
    
    TPAlertView * alertVC = [[TPAlertView alloc]initOkWithTitle:str subtitle:nil];
//    [self presentViewController:alertVC animated:YES completion:nil];
    [[TPAlertViewController defaultCautionViewController] showAlertView:alertVC animated:YES];
}

- (void)showHUDWithReqModel:(nonnull TPBaseNetModel_req * )reqModel
                   progress:(nullable void(^)(NSProgress * _Nullable downloadProgress )) downloadProgress
            successGetModel:(nonnull void (^)(TPBaseNetModel_res * _Nullable resModel))successGetModel
            failureGetModel:(nonnull void (^)(TPBaseNetModel_res * _Nullable resModel))failureGetModel
{

        TPAlertView * alertVC_HUD_loading = [TPAlertView sharedHUDView_Loading];

    [[TPAlertViewController defaultHUDViewController]showAlertView:alertVC_HUD_loading animated:YES];
    

    NSURLSessionDataTask * task = [[TPNetworkingManager manager] TP_Cac_requestWithReqModel:reqModel progress:downloadProgress successGetModel:^(TPBaseNetModel_res * _Nullable resModel) {
//        dispatch_group_leave(HUD_group);
        [alertVC_HUD_loading dismissAnimated:YES];
        
        successGetModel(resModel);
        

    } failureGetModel:^(TPBaseNetModel_res * _Nullable resModel) {
//        dispatch_group_leave(HUD_group);
        [alertVC_HUD_loading dismissAnimated:YES];
//        [alertVC_HUD_loading dismissViewControllerAnimated:YES completion:^{
            failureGetModel(resModel);
//        }];
        
    }];

    [alertVC_HUD_loading setAlertViewTapBtnCancelBlock:^(id objec) {
                [task cancel];
    }];

}

////runtime 设置 属性
//-(void)setAlertVC_HUD_loading:(TPAlertViewController *)alertVC_HUD_loading{
//    objc_setAssociatedObject(self, &alertVC_HUD_loadingKey, alertVC_HUD_loading, OBJC_ASSOCIATION_RETAIN);
//}
//-(TPAlertViewController *)alertVC_HUD_loading{
//    return objc_getAssociatedObject(self, &alertVC_HUD_loadingKey);
//}

@end
